#!groovy loadConfiguration.groovy 
//解析整个yaml对object，返回给调用方
import com.jenkins.devops.Artifact
import com.jenkins.devops.Dockerization

def call(Map kwArgs = [:]) {
    def artifact = loadArtifact(kwArgs)
    return artifact
}


def loadArtifact(Map kwArgs = [:]) {
    Artifact artifact = new Artifact()
    def type = kwArgs['filePath']
    def data = readYaml(file: type)

    artifact.setName(data.name ?: '')
    artifact.setProjectName(data.projectName ?: '')
    artifact.setEnableUnitTest(data.enableUnitTest ?: '')
    artifact.setEnableCucumberTest(data.enableCucumberTest ?: '')
    artifact.setNeedDockerImage(data.needDockerImage == 'false' ? false : true)
    if (data.needDockerImage) {
        def dockerImages = data.dockerImages
        for (Map imageMap in dockerImages) {
            Dockerization dockerImage = new Dockerization()
            dockerImage.dockerfile = imageMap['dockerfile']
            dockerImage.path = imageMap['path']
            artifact.dockerImages << dockerImage
        }
    }
    artifact.setNotificationEmails(data.notificationEmails)
    return artifact
}